var QXYM = 'qxwl.njqxq.gov.cn';
var QXSSO = 'http://tyrz.njqxq.gov.cn/sso/logout?service=http://qxwl.njqxq.gov.cn/BFirePM/sso';
var loginUser = new Object();
var isLogin = new Object(); //用来判断是否为登录中
var count = 15;
var totalPage = 1;
var currentPage = 1;
var webSocket;
var tryTime = 0;
var userId = null;

var imgurl = 'http://www.njdtwise.com:3399/images/'
// var arrsysmodule = ['org', 'orgadm', 'module', 'modadm', 'account', 'accadm', 'area', 'areadm', 'app', 'appadm', 'uiadm'];
var arrsysmodule = ['org', 'orgadm', 'module', 'modadm', 'account', 'accadm', 'area', 'areadm', 'uiadm', 'repair', 'message'];
var arrloginmodule = [];
var appid = '';
$(document).ready(function() {
    // $(document).ajaxError(function(event, xhr, options, exc) {

    //     if (xhr.responseText.indexOf(401) > -1) {
    //         loginOut()
    //     }
    // })
	
	$(document).ajaxError(function (event, xhr, options, exc) {
		console.log('200')
	    if (xhr.status == 200) {
	        loginOut()
	    }
	})
	$(document).ajaxSuccess(function (event, xhr, options, exc) {
		console.log('401')
	    if (JSON.parse(xhr.responseText).status == 401) {
	
	        loginOut()
	    }
	
	})
	
    isLogin = localStorage.getItem('isLogin');
    if (isLogin != null && isLogin != "") {
        var obj = JSON.parse(localStorage.getItem("isLogin"));
        userId = obj.userid;
        Cookies.set('sessionid', obj.sessionid);

    }

/*    try {
        initWebSocket();
    } catch (err) {
        console.log(err)
    }*/
    hideMenu();
    appid = localStorage.getItem("appid");
    superrootmodules1(appid);
    var _url = window.location.pathname;
    var currentBar = $('#menu ul li');
    $.each(currentBar, function(index, el) {
        if ($(el).find('a').attr('href') == _url) {
            $('#menu ul li').removeClass('colors');
            $(el).addClass('colors');
        }
    })



});
/*显示在页面中的时间*/
function getSystemDate() {
    var date = new Date();
    $("#system_year").html(date.getFullYear());
    $("#system_month").html(date.getMonth() + 1);
    $("#system_day").html(date.getDate());
}

function cutStr(str, num) {
    let newStr = str.length > num ? str.substring(0, num) + '...' : str;
    return newStr;
}
//操作Cookie
var Cookies = new Object();
Cookies.set = function(name, value) {
    var argv = arguments;
    var argc = arguments.length;
    var expires = (argc > 2) ? argv[2] : null;
    var path = (argc > 3) ? argv[3] : '/';
    var domain = (argc > 4) ? argv[4] : null;
    var secure = (argc > 5) ? argv[5] : false;
    document.cookie = name + "=" + escape(value) +
        ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
        ((path == null) ? "" : ("; path=" + path)) +
        ((domain == null) ? "" : ("; domain=" + domain)) +
        ((secure == true) ? "; secure" : "");
};

Cookies.get = function(name) {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    var j = 0;
    while (i < clen) {
        j = i + alen;
        if (document.cookie.substring(i, j) == arg)
            return Cookies.getCookieVal(j);
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0)
            break;
    }
    return null;
};

Cookies.clear = function(name) {
    if (Cookies.get(name)) {
        document.cookie = name + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
};

Cookies.getCookieVal = function(offset) {
    var endstr = document.cookie.indexOf(";", offset);
    if (endstr == -1) {
        endstr = document.cookie.length;
    }
    return unescape(document.cookie.substring(offset, endstr));
};
//操作Cookie

function login() {
    $('#login-msg').find('label').eq(0).html('');
    var accout = $("#username").val();
    var password = $("#password").val();
    localStorage.setItem("accout1", accout);
    localStorage.setItem("password", password);
    var url = '/rest/account/login';
    $.ajax({
        url: url,
        type: "POST",
        contentType: "application/json",
        data: JSON.stringify({
            "account": accout,
            "password": password
        }),
        success: function(data) {
            var data = eval("(" + data + ")");
            var sunccess = data.ret.success;
            if (sunccess == true) {
                var func = data.func;
                var account = data.args.account;
                var message = data.ret.message;
                var name = data.ret.value.name;
                var role = data.ret.value.role;
                var expires = data.ret.value.expires;
                localStorage.removeItem("indexeuid");
                loginUser = data.ret.value;
                loginUser["account"] = account; /**/
                localStorage.setItem("account", account);
                Cookies.set('loginUser', JSON.stringify(loginUser));
                /* document.cookie='loginUser'+'='+JSON.stringify(loginUser)*/
                localStorage.setItem('isLogin', JSON.stringify(loginUser));
                if (window.location.href.indexOf('login_qx') > -1) {
                    localStorage.setItem("isqx", 1);
                }
               window.location.href = "/esac/html/frontPage/firedoor.html";
            } else {
                $('#login-msg').find('label').eq(0).html('用户名或密码错误');
            }
        },
        error: function(result) {

        }
    });
}

function Ajax(url, callBack, parms, type) {
    $.ajax({
        url: url,
        type: type ? type : 'get',
        data: parms ? parms : '',
        contentType: "application/json",
        success: function(result) {
            let data = JSON.parse(result);
            callBack(data);
        }
    });
}

function AjaxRequest(url, callBack, parms, type) {
    $.ajax({
        url: '/rest/v2' + url,
        type: type ? type : 'get',
        data: parms ? JSON.stringify(parms) : '',
        contentType: "application/json",
        success: function(result) {

            callBack(result);

        }
    });
}


function reback() {
    var appid = localStorage.getItem('appid');
    let isLogin = JSON.parse(localStorage.getItem('isLogin'));
    let orgType = isLogin.orgType;
    if (appid == 15) {
        window.location.href = "/waterq/waterquality/html/index.html";
    } else if (appid == 24) {
        window.location.href = "/scity/index.html";
    } else {
        if (orgType == 2) {
            window.location.href = "/FirePM/html/homepage.html"
        } else {
            window.location.href = "/FirePM/html/index/index.html";
        }
    }
}


function logout() {
    layer.confirm('确定退出系统？', {
        btn: ['确定', '取消'] //按钮
    }, function() {
        localStorage.removeItem("indexeuid");
        // if (localStorage.getItem('appid') == 15) {
        //     loginOut1();
        // } else if (localStorage.getItem('isqx') == 1) {
        //     loginOut_qx();
        // } else {
        //     loginOut();
        // }
		loginOut();
    });
}

function loginOut() {
    $.ajax({
        url: '/rest/account/logout',
        type: "post",
        contentType: "application/json",
        success: function(result) {
            localStorage.setItem('isLogin', "");
            localStorage.setItem('appid', "");
            localStorage.setItem('pId', "");
			
			window.location.href = "/fireapply/html/login.html";
            // if (window.location.href.indexOf(QXYM) > 0) {
            //     window.location.href = QXSSO;
            // } else {
            //     window.location.href = "/fireapply/html/login.html";
            // }
        },
        error: function(result) {
            localStorage.setItem('isLogin', "");
            localStorage.setItem('appid', "");
			window.location.href = "/fireapply/html/login.html";
            // if (window.location.href.indexOf(QXYM) > 0) {
            //     window.location.href = QXSSO;
            // } else {
            //     window.location.href = "/esac/html/login.html";
            // }
        }
    })
}

function loginOut_qx() {
    $.ajax({
        url: '/rest/account/logout',
        type: "post",
        contentType: "application/json",
        success: function(result) {
            /*if (localStorage.getItem('appid') == 15) {
                localStorage.setItem('isLogin', "");
                 localStorage.setItem('appid', "");
                 window.location.href = "/waterq/html/login.html";
             } else {
                 localStorage.setItem('isLogin', "");
                 localStorage.setItem('appid', "");
                 window.location.href = "/FirePM/html/login.html";
             }*/
            localStorage.setItem('isLogin', "");
            localStorage.setItem('appid', "");
            localStorage.setItem('isqx', "");
            /*if(window.location.href.indexOf("qxwl.njqxq.gov.cn")>0) {
                window.location.href="http://tyrz.njqxq.gov.cn/sso/logout?service=http://qxwl.njqxq.gov.cn:3390/BFirePM";
             }
             else {
                 window.location.href = "/FirePM/html/login.html";
             }*/
            if (window.location.href.indexOf(QXYM) > 0) {
                window.location.href = QXSSO;
            } else {
                window.location.href = "/FirePM/html/login_qx.html";
            }
        },
        error: function(result) {
            /*if (localStorage.getItem('appid') == 15) {
                localStorage.setItem('isLogin', "");
                localStorage.setItem('appid', "");
                window.location.href = "/waterq/html/login.html";
            } else {
                localStorage.setItem('isLogin', "");
                localStorage.setItem('appid', "");
                window.location.href = "/FirePM/html/login.html";
            }*/
            localStorage.setItem('isLogin', "");
            localStorage.setItem('appid', "");

            /*if(window.location.href.indexOf("qxwl.njqxq.gov.cn")>0) {
                window.location.href="http://tyrz.njqxq.gov.cn/sso/logout?service=http://qxwl.njqxq.gov.cn:3390/BFirePM";
             }
             else {
                 window.location.href = "/FirePM/html/login.html";
             }*/
            if (window.location.href.indexOf(QXYM) > 0) {
                window.location.href = QXSSO;
            } else {
                window.location.href = "/FirePM/html/login.html";
            }
        }
    })
}

function loginOut1() {
    $.ajax({
        url: '/rest/account/logout',
        type: "post",
        contentType: "application/json",
        success: function(result) {
            localStorage.setItem('isLogin', "");
            localStorage.setItem('appid', "");
            /*$.cookie('name', '', { expires: -1, path: '/' });
            $.cookie('orgid', '', { expires: -1, path: '/' });*/
            localStorage.clear();
            /*$.session.set('name', '');
            $.session.clear();*/
            /*if(window.location.href.indexOf("qxwl.njqxq.gov.cn")>0) {
                window.location.href="http://tyrz.njqxq.gov.cn/sso/logout?service=http://qxwl.njqxq.gov.cn:3390/BFirePM";
             }
             else {
                window.location.href = "/waterq/html/login.html";
             }*/
            if (window.location.href.indexOf(QXYM) > 0) {
                window.location.href = QXSSO;
            } else {
                window.location.href = "/waterq/html/login.html";
            }
        },
        error: function(result) {
            localStorage.setItem('isLogin', "");
            localStorage.setItem('appid', "");
            /* $.cookie('name', '', { expires: -1, path: '/' });
             $.cookie('orgid', '', { expires: -1, path: '/' });*/
            /*if(window.location.href.indexOf("qxwl.njqxq.gov.cn")>0) {
                window.location.href="http://tyrz.njqxq.gov.cn/sso/logout?service=http://qxwl.njqxq.gov.cn:3390/BFirePM";
             }
             else {
                window.location.href = "/waterq/html/login.html";
             }*/
            if (window.location.href.indexOf(QXYM) > 0) {
                window.location.href = QXSSO;
            } else {
                window.location.href = "/waterq/html/login.html";
            }
        }
    })
}
/*设置时间格式*/
function setTimeFormate(rowIndex, rowData) {
    if (rowData.time == "" || rowData.time == null) {
        return "";
    } else {
        var datastr = rowData.time;
        rowData.time = datastr.substr(0, 10) + "&nbsp;&nbsp;&nbsp;" + datastr.substr(11, 8);
        return rowData.time;
    }
}
/*选择当前这个页面对应的导航*/
function setActiveMenu(currentId) {

    if ($("#" + currentId).attr("class") == "menu_item") {
        $("#" + currentId).attr("class", "menu_item menu_item_activate").siblings().attr("class", "menu_item")
    }
}
/*根据选择的导航进入相应的页面*/
function gotoPage(id) {
    if (id.substr(0, 4) == 'menu') {
        window.location.href = "../../html/biz/" + id.substr(5) + ".html";
    } else {
        window.location.href = "../../html/biz/" + id + ".html";
    }
}

function preLoadImg(arr) {
    for (var i = 0; i < arr.length; i++) {
        var img = new Image();
        img.src = arr[i];
    }
}

function Judgeidentity() {
    isLogin = localStorage.getItem('isLogin');
    if (isLogin == null || isLogin == "") {
        if (window.location.href.indexOf("waterquality") < 0) {
            window.location.href = "/esac/html/login/login.html";
        } else {
            window.location.href = "../../html/login/login.html";
        }
    } else {
        var role = isLogin.role;
        if (window.location.href.indexOf("superroot") < 0) {
            $("#menu_system").attr("style", "display: none;");
        }
        $("#admin-user span").eq(1).text("用户")
    }
}


$(".popupTitle-right img").bind("click", function() {
    $(".popupMessageBox").hide();

})
$(".popupBottom-cancel").click(function() {
    $(".popupMessageBox").hide();
})

if ((window.location.href.indexOf("node") > 0 || window.location.href.indexOf("warn") > 0 ||
        window.location.href.indexOf("repair") > 0)) {
    if (window.location.href.indexOf("TheFirePool") > 0 || window.location.href.indexOf("firestationpool") > 0) {
        $('#gridRepairTable').datagrid({
            //双击事件
            onDblClickRow: function(rowIndex, rowData) {
                $(".address-right").html(rowData.address);
                $(".product-right").html(rowData.seuid);
                $(".time-right").html(rowData.time);
                $(".simid-right").html(rowData.sim_id);
                $(".pressure-right").html(rowData.depth * rowData.width * rowData.longs / 1000000000 + 't');
                if (rowData.depth / rowData.height > 0.5) {
                    var status = '液位正常'
                } else {
                    var status = '液位过低'

                }
                $(".status-right").html(status);
                $(".longitude-right").html(rowData.west);
                $(".latitude-right").html(rowData.north);
                $(".signal-right").html(getCureentXH(rowData.signal));
                $(".popupMessageBox").show();
                $(".voltage-right").html(rowData.voltage);
            }
        })
    } else if (window.location.href.indexOf("firedoor") > 0) {
        $('#gridRepairTable').datagrid({
            //双击事件
            onDblClickRow: function(rowIndex, rowData) {
                $(".address-right").html(rowData.address);
                $(".product-right").html(rowData.seuid);
                $(".simid-right").html(rowData.sim_id);

                $(".time-right").html(rowData.time);
                $(".voltage-right").html(rowData.voltage);
                $(".status-right").html(function() {
                    if (rowData.warning_status == null) {
                        value = "数据异常";
                    } else {
                        var value1 = rowData.warning_status;
                        if (value1 == 1) { value = "门开告警"; } else { value = "正常"; }
                    }
                    return value;
                });
                $(".longitude-right").html(rowData.west);
                $(".latitude-right").html(rowData.north);
                $(".signal-right").html(getCureentXH(rowData.signal));
                $(".popupMessageBox").show();
            }
        })
    } else if (window.location.href.indexOf("distributionbox") > 0) {
        $('#gridRepairTable').datagrid({
            //双击事件
            onDblClickRow: function(rowIndex, rowData) {
                $(".address-right").html(rowData.address);
                $(".product-right").html(rowData.seuid);
                $(".time-right").html(rowData.time);
                $(".pressure-right").html(rowData.sim_id);
                $(".status-right").html(function() {
                    if (rowData.a_temperature == null || rowData.b_temperature == null || rowData.c_temperature == null || rowData.current == null) {
                        value = "数据异常";
                    } else {
                        var value1 = rowData.a_temperature;
                        var value2 = rowData.b_temperature;
                        var value3 = rowData.c_temperature;
                        var value4 = rowData.current;
                        if (value1 <= 120 && value2 <= 120 && value3 <= 120 && value4 <= 5) {
                            value = "正常";
                        } else if ((value1 > 120 || value2 > 120 || value3 > 120) && value4 <= 5) {
                            value = "温度过高";
                        } else if ((value1 <= 120 && value2 <= 120 && value3 <= 120) && value4 > 5) {
                            value = "漏电";
                        } else if ((value1 > 120 || value2 > 120 || value3 > 120) && value4 > 5) {
                            value = "超温漏电";
                        } else {
                            value = "数据异常";
                        }
                    }
                    return value;
                });
                $(".longitude-right").html(rowData.west);
                $(".latitude-right").html(rowData.north);
                $(".signal-right").html(getCureentXH(rowData.signal));
                $(".popupMessageBox").show();
            }
        })
    } else if (window.location.href.indexOf("intelligentPatrol") > 0) {
        $('#gridRepairTable').datagrid({
            //双击事件
            onDblClickRow: function(rowIndex, rowData) {
                $(".address-right").html(rowData.name);
                $(".product-right").html(rowData.account);
                $(".simid-right").html(rowData.principal);
                $(".time-right").html(rowData.telephone);
                $(".pressures-right").html(rowData.member);
                $(".status-right").html(rowData.describtion);
                $(".popupMessageBox").show();
            }
        })
    } else if (window.location.href.indexOf("smokemonitor") > 0) {
        $('#gridRepairTable').datagrid({
            //双击事件
            onDblClickRow: function(rowIndex, rowData) {
                $(".address-right").html(rowData.address);
                $(".product-right").html(rowData.seuid);
                $(".simid-right").html(rowData.sim_id);
                $(".time-right").html(rowData.time);
                $(".status-right").html(function() {
                    if (rowData.status == 1) {
                        value = "正常";
                    } else if (rowData.status == 2) {
                        value = "火警报警"
                    } else if (rowData.status == 3) {
                        value = "火警欠压"
                    } else if (rowData.status == 4) {
                        value = "低电量火警报警消失"
                    } else if (rowData.status == 5) {
                        value = "火警报警消失"
                    } else if (rowData.status == 6) {
                        value = "低电量报警"
                    } else if (rowData.status == 7) {
                        value = "低电量报警消失"
                    } else if (rowData.status == 255) {
                        value = "离线"
                    } else if (rowData.status == 50) {
                        value = "火警取消"
                    } else if (rowData.status == 55) {
                        value = "火警"
                    } else if (rowData.status == 205) {
                        value = "光源污染"
                    } else if (rowData.status == 206) {
                        value = "光源污染恢复"
                    } else if (rowData.status == 38) {
                        value = "电池欠压"
                    } else if (rowData.status == 39) {
                        value = "电池欠压恢复"
                    } else if (rowData.status == 23) {
                        value = "传感器故障"
                    } else if (rowData.status == 24) {
                        value = "传感器恢复"
                    } else if (rowData.status == 11) {
                        value = "报警"
                    } else if (rowData.status == 12) {
                        value = "报警静音"
                    } else if (rowData.status == 13) {
                        value = "故障"
                    } else if (rowData.status == 14) {
                        value = "低压"
                    } else if (rowData.status == 15) {
                        value = "/"
                    } else if (rowData.status == 16) {
                        value = "/"
                    } else if (rowData.status == 17) {
                        value = "正常"
                    } else if (rowData.status == 8) {
                        value = "数据异常"
                    }
                    return value;
                });
                $(".longitude-right").html(rowData.west);
                $(".latitude-right").html(rowData.north);
                $(".signal-right").html(getCureentXH(rowData.signal));
                $(".popupMessageBox").show();
            }
        })
    } else {
        $('#gridRepairTable').datagrid({
            //双击事件
            onDblClickRow: function(rowIndex, rowData) {
                $(".address-right").html(rowData.address);
                $(".product-right").html(rowData.seuid);
                $(".simid-right").html(rowData.sim_id);

                $(".time-right").html(rowData.time);
                $(".voltage-right").html(rowData.voltage);
                if (rowData.status == 255) {
                    var pressure = "离线"
                } else if (rowData.pressure == null) {
                    var pressure = ""
                    var status = ""
                } else {
                    var value = rowData.pressure / 1000000.0;
                    var pressure = value + "MPa";
                    if (value >= 0.1) { status = "水压充足" } else if (value >= 0.05) { status = "水压正常"; } else if (value >= 0.005) { status = "水压不足"; } else if (value < 0.005) { status = "水压严重不足" }
                }
                $(".pressure-right").html(pressure);
                $(".product-right").html(rowData.seuid);
                $(".status-right").html(status);
                $(".longitude-right").html(rowData.west);
                $(".latitude-right").html(rowData.north);
                $(".signal-right").html(getCureentXH(rowData.signal));
                $(".popupMessageBox").show();
            }
        })
    }
}
if (window.location.href.indexOf("maintenanceequip") > 0) {
    $('#gridRepairTable').datagrid({
        //双击事件
        onDblClickRow: function(rowIndex, rowData) {
            $(".address-right").text(rowData.id);
            $(".euidright").text(rowData.euid);
            $(".simid-right").html(rowData.sim_id);

            $(".repair_personright").text(rowData.repair_person);
            $(".telephoneright").text(rowData.telephone);
            $(".repair_timeright").text(function() {
                if (rowData.repair_time == "" || rowData.repair_time == null) {
                    return "";
                } else {
                    var datastr = rowData.repair_time;
                    rowData.repair_time = datastr.substr(0, 10) + " " + datastr.substr(11, 8);
                    return rowData.repair_time;
                }
            });
            $(".repair_titleright").text(rowData.repair_title);
            $(".repair_contentright").text(rowData.repair_content);
            $(".status-right").text(rowData.module);
            $(".createtime-right").text(function() {
                if (rowData.create_time == "" || rowData.create_time == null) {
                    return "";
                } else {
                    var datastr = rowData.create_time;
                    rowData.create_time = datastr.substr(0, 10) + " " + datastr.substr(11, 8);
                    return rowData.create_time;
                }
            });
            $(".popupMessageBox").show();
        }
    })
}

/*if (window.location.href.indexOf("geomagnetism") > 0) {
    $('#gridRepairTable').datagrid({
        //双击事件
        onDblClickRow: function(rowIndex, rowData) {
            $(".address-right").html(rowData.address);
            $(".product-right").html(rowData.seuid);
            $(".simid-right").html(rowData.simId);

            $(".time-right").html(rowData.time);
            $(".voltage-right").html(rowData.voltage);
            $(".status-right").html(function() {
                if (rowData.status == 255) {
                    value = "离线";
                } else {
                    var value1 = rowData.status;
                    if (value1 == 1) { value = "车位告警"; } else { value = "正常"; }
                }
                return value;
            });
            $(".longitude-right").html(rowData.west);
            $(".latitude-right").html(rowData.north);
            $(".dataType-right").html(rowData.dataType);
            $(".signal-right").html(getCureentXH(rowData.signal));
            $(".popupMessageBox").show();
        }
    })
}*/

if (window.location.href.indexOf("soak") > 0) {
    $('#gridRepairTable').datagrid({
        //双击事件
        onDblClickRow: function(rowIndex, rowData) {
            $(".address-right").html(rowData.address);
            $(".product-right").html(rowData.seuid);
            $(".simid-right").html(rowData.simId);

            $(".time-right").html(rowData.time);
            $(".voltage-right").html(rowData.voltage);
            $(".status-right").html(function() {
                if (rowData.status == 255) {
                    value = "离线";
                } else {
                    var value1 = rowData.status;
                    if (value1 == 1) { value = "浸水告警"; } else { value = "正常"; }
                }
                return value;
            });
            $(".longitude-right").html(rowData.west);
            $(".latitude-right").html(rowData.north);
            $(".signal-right").html(getCureentXH(rowData.signal));
            $(".popupMessageBox").show();
        }
    })
}

function getCureentXH(value) {
    if (value == null) {
        $(".rowContent-communicate").hide();
        return " ";
    } else if (value <= 31 && value >= 0) {
        $(".rowContent-communicate").hide();
        return value;
    } else if (value >= 32 && value <= 63) {
        var value1 = value - 32;
        $(".rowContent-communicate").show();
        $(".communicate-right").text('NBIOT');
        return value1;
    } else if (value >= 64 && value <= 95) {
        $(".rowContent-communicate").show();
        $(".communicate-right").text('GSM');
        var value2 = value - 64;
        return value2;
    }
}

function getpressureValue(value) {
    if (value == null) {
        return " ";
    } else {
        var mpa = value / 1000000.0;
        return mpa + "MPa";
    }
}

function getstatus(values) {
    if (values == null) {
        value = "离线"
    } else {
        var value = values / 1000000.0;
        if (value >= 0.1) { value = "水压充足" } else if (value >= 0.05) { value = "水压正常"; } else if (value >= 0.005) { value = "水压不足"; } else if (value < 0.005 && value >= 0) { value = "水压严重不足" }
    }
    return value;
}
if (window.location.href.indexOf("firepump/html/biz/node") > 0 || window.location.href.indexOf("firepump/html/biz/warn") > 0 ||
    window.location.href.indexOf("firepump/html/biz/repair") > 0) {
    $('#gridRepairTable').datagrid({
        //双击事件
        onDblClickRow: function(rowIndex, rowData) {
            $(".address-right").html(rowData.address);
            $(".product-right").html(rowData.seuid);
            $(".time-right").html(rowData.time);
            $(".pressure-right").html(getpressureValue(rowData.pressure));
            $(".status-right").html(function() {
                if (rowData.status == 255) {
                    value = "离线"
                } else if (rowData.pressure >= 200000) {
                    value = "水压充足";
                } else if (rowData.pressure < 200000) {
                    value = "水压不足"
                } else {
                    value = "数据异常"
                }
                return value;
            });
            $(".longitude-right").html(rowData.west);
            $(".latitude-right").html(rowData.north);
            $(".signal-right").html(getCureentXH(rowData.signal));
            $(".popupMessageBox").show();
            $(".simid-right").html(rowData.sim_id);
            $(".voltage-right").html(rowData.voltage);
        }
    })

}

function hidemsg() {
    $("#errormsg").attr("style", "display:none");
}

Date.prototype.Format = function(fmt) {
    var o = {
        "M+": this.getMonth() + 1, //月份  
        "d+": this.getDate(), //日  
        "h+": this.getHours(), //小时  
        "m+": this.getMinutes(), //分  
        "s+": this.getSeconds(), //秒  
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度  
        "S": this.getMilliseconds() //毫秒  
    };
    if (/(y+)/.test(fmt))
        fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt))
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}
//全屏显示与退出
function requestFullScreen(element) {
    var requestMethod = element.requestFullScreen || element.webkitRequestFullScreen || element.mozRequestFullScreen || element.msRequestFullScreen;
    if (requestMethod) {
        requestMethod.call(element);
    } else if (typeof window.ActiveXObject != "undefined") {

        var wscript = new ActiveXObject("WScript.Shell");
        if (wscript != null) {
            wscript.SendKeys("{F11}");

        }

    }
}



function checkFull() {
    var isFull = document.fullscreenEnabled || window.fullScreen || document.webkitIsFullScreen || document.msFullscreenEnabled;
    if (isFull === undefined) isFull = false;
    return isFull;
}

function exitFullscreen() {
    if (document.exitFullscreen) {
        document.exitFullscreen();
    } else if (document.mozCancelFullScreen) {
        document.mozCancelFullScreen();
    } else if (document.webkitExitFullscreen) {
        document.webkitExitFullscreen();
    }
}
//地图页面全屏
$('.quan').click(function() {
    var elem = document.getElementById("monitor-map");
    $('.quan').attr('style', 'display:none');
    $('.quanping').attr('style', 'display:block');
    $('#monitor-map').attr('style', 'height:100%;width:100%');
    requestFullScreen(elem);
})

$('.quanping').click(function() {
    exitFullscreen();
    $('.quan').attr('style', 'display:block');
    $('.quanping').attr('style', 'display:none');
    $('#monitor-map').attr('style', '');

})

window.onresize = function() {
    if (!checkFull()) {
        $('.quan').attr('style', 'display:block');
        $('.quanping').attr('style', 'display:none');
        $('#monitor-map').attr('style', '');
    }
}
//隐藏分页的首页尾页两个按钮
function paginationno(id) {
    for (var i = 0; i < $("#" + id + " a").size(); i++) {
        if ($("#" + id + " a").eq(i).html() != '首页' && $("#" + id + " a").eq(i).html() != '尾页') {
            $("#" + id + " a").eq(i).css('display', 'initial')
        }
    }
}

//导出excel----------begin-------
var tmpDown; //导出的二进制对象


function s2ab(s) { //字符串转字符流
    var buf = new ArrayBuffer(s.length);
    var view = new Uint8Array(buf);
    for (var i = 0; i != s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF;
    return buf;
}
// 将指定的自然数转换为26进制表示。映射关系：[0-25] -> [A-Z]。
function getCharCol(n) {
    var temCol = '';
    var s = '';
    var m = 0
    while (n > 0) {
        m = n % 26 + 1
        s = String.fromCharCode(m + 64) + s
        n = (n - m) / 26
    }
    return s
}
//导出excel-------------------------end
//损坏报警弹窗
/*function openthemsg(num) {
    if (num > 0) {
        $('#pop').slideDown();
        $('#warnnum').html(num);
    } else {
        $('#pop').slideUp();
        $('#warnnum').html('');
    }
}
$('#popMore span').click(function() {
    window.location.href = "warn.html";
})

function firedoorwarnnum() {
    var pattern = "%25";
    var url = '/rest/fireDoorDamangeAlarm/list_issue?seuid=' + pattern + '&sim_id=' + pattern + '&address=' + pattern + '&from' + '&count';
    $.ajax({
        url: url,
        type: "get",
        contentType: "application/json",
        success: function(result) {
            result = eval("(" + result + ")");
            var total = result.ret.total;
            openthemsg(total);
        },
        error: function(result) {}
    });
}*/

//gps坐标转换
function tdGps(parm) {
    var tdGps = [];
    var bd09togcj02;
    var gcj02towgs84;
    bd09togcj02 = coordtransform.bd09togcj02(parm.west, parm.north);
    gcj02towgs84 = coordtransform.gcj02towgs84(bd09togcj02[0], bd09togcj02[1]);
    tdGps[0] = gcj02towgs84[0] - 0.00003;
    tdGps[1] = gcj02towgs84[1] - 0.00007;
    parm.east = tdGps[0];
    parm.north = tdGps[1];
    return parm;
}

//三级菜单
function superrootmodules1(appid) {
    if (localStorage.getItem("isLogin")) {
        var usemodel = JSON.parse(localStorage.getItem("isLogin")).ui;
        var num = 0;
        var menu = ''
        for (var i = 0; i < usemodel.length; i++) {

            if (usemodel[i].type == 3 && usemodel[i].status == 1) {
                if (usemodel[i].appid == appid) {
                    if (appid == 1) {
                        if (document.location.href.indexOf(usemodel[i].url) > -1) {
                            menu = menu + '<li class="menu_item"><a href="/FirePM/firehydrant/html/biz' + usemodel[i].url + '"><div style="width: 100%;padding-left: 25%;" class="menu_text"><span style="font-size: 20px;margin-right: 10px;" class=' + usemodel[i].icon + '></span>' + usemodel[i].name + '</div></a></li>';
                        } else {
                            menu = menu + '<li class="menu_item"><a href="/FirePM/firehydrant/html/biz' + usemodel[i].url + '"><div style="width: 100%;padding-left: 25%;" class="menu_text"><span style="font-size: 20px;margin-right: 10px;" class=' + usemodel[i].icon + '></span>' + usemodel[i].name + '</div></a></li>';
                        }
                        num = num + 1;
                    } else if (appid == 7) {
                        if (document.location.href.indexOf(usemodel[i].url) > -1) {
                            menu = menu + '<li class="menu_item"><a href="/FirePM/firepump/html/biz' + usemodel[i].url + '"><div style="width: 100%;padding-left: 25%;" class="menu_text"><span style="font-size: 20px;margin-right: 10px;" class=' + usemodel[i].icon + '></span>' + usemodel[i].name + '</div></a></li>';
                        } else {
                            menu = menu + '<li class="menu_item"><a href="/FirePM/firepump/html/biz' + usemodel[i].url + '"><div style="width: 100%;padding-left: 25%;" class="menu_text"><span style="font-size: 20px;margin-right: 10px;" class=' + usemodel[i].icon + '></span>' + usemodel[i].name + '</div></a></li>';
                        }
                        num = num + 1;
                    } else if (appid == 2) {
                        if (document.location.href.indexOf(usemodel[i].url) > -1) {
                            menu = menu + '<li class="menu_item"><a href="/FirePM/showerhead/html/biz' + usemodel[i].url + '"><div style="width: 100%;padding-left: 25%;" class="menu_text"><span style="font-size: 20px;margin-right: 10px;" class=' + usemodel[i].icon + '></span>' + usemodel[i].name + '</div></a></li>';
                        } else {
                            menu = menu + '<li class="menu_item"><a href="/FirePM/showerhead/html/biz' + usemodel[i].url + '"><div style="width: 100%;padding-left: 25%;" class="menu_text"><span style="font-size: 20px;margin-right: 10px;" class=' + usemodel[i].icon + '></span>' + usemodel[i].name + '</div></a></li>';
                        }
                        num = num + 1;
                    } else if (appid == 6) {
                        if (document.location.href.indexOf(usemodel[i].url) > -1) {
                            menu = menu + '<li class="menu_item"><a href="/FirePM/smokemonitor/html/biz' + usemodel[i].url + '"><div style="width: 100%;padding-left: 25%;" class="menu_text"><span style="font-size: 20px;margin-right: 10px;" class=' + usemodel[i].icon + '></span>' + usemodel[i].name + '</div></a></li>';
                        } else {
                            menu = menu + '<li class="menu_item"><a href="/FirePM/smokemonitor/html/biz' + usemodel[i].url + '"><div style="width: 100%;padding-left: 25%;" class="menu_text"><span style="font-size: 20px;margin-right: 10px;" class=' + usemodel[i].icon + '></span>' + usemodel[i].name + '</div></a></li>';
                        }
                        num = num + 1;
                    } else if (appid == 5) {
                        if (document.location.href.indexOf(usemodel[i].url) > -1) {
                            menu = menu + '<li class="menu_item"><a href="/FirePM/firestationpool/html/biz' + usemodel[i].url + '"><div style="width: 100%;padding-left: 25%;" class="menu_text"><span style="font-size: 20px;margin-right: 10px;" class=' + usemodel[i].icon + '></span>' + usemodel[i].name + '</div></a></li>';
                        } else {
                            menu = menu + '<li class="menu_item"><a href="/FirePM/firestationpool/html/biz' + usemodel[i].url + '"><div style="width: 100%;padding-left: 25%;" class="menu_text"><span style="font-size: 20px;margin-right: 10px;" class=' + usemodel[i].icon + '></span>' + usemodel[i].name + '</div></a></li>';
                        }
                        num = num + 1;
                    } else if (appid == 9) {
                        if (document.location.href.indexOf(usemodel[i].url) > -1) {
                            menu = menu + '<li class="menu_item"><a href="/FirePM/firedoor/html/biz' + usemodel[i].url + '"><div style="width: 100%;padding-left: 25%;" class="menu_text"><span style="font-size: 20px;margin-right: 10px;" class=' + usemodel[i].icon + '></span>' + usemodel[i].name + '</div></a></li>';
                        } else {
                            menu = menu + '<li class="menu_item"><a href="/FirePM/firedoor/html/biz' + usemodel[i].url + '"><div style="width: 100%;padding-left: 25%;" class="menu_text"><span style="font-size: 20px;margin-right: 10px;" class=' + usemodel[i].icon + '></span>' + usemodel[i].name + '</div></a></li>';
                        }
                        num = num + 1;
                    } else if (appid == 16) {
                        if (document.location.href.indexOf(usemodel[i].url) > -1) {
                            menu = menu + '<li class="menu_item active" ><a href="/FirePM/electric/html' + usemodel[i].url + '"><span class=' + usemodel[i].icon + '></span>' +
                                '<span class="title">' + usemodel[i].name + '</span></a></li>';
                        } else {
                            menu = menu + '<li><a href="/FirePM/electric/html' + usemodel[i].url + '"><span class=' + usemodel[i].icon + '></span>' +
                                '<span class="title">' + usemodel[i].name + '</span></a></li>';
                        }
                    } else if (appid == 17) {
                        if (document.location.href.indexOf(usemodel[i].url) > -1) {
                            menu = menu + '<li class="menu_item active" ><a href="/FirePM/order/html' + usemodel[i].url + '"><span class=' + usemodel[i].icon + '></span>' +
                                '<span class="title">' + usemodel[i].name + '</span></a></li>';
                        } else {
                            menu = menu + '<li><a href="/FirePM/order/html' + usemodel[i].url + '"><span class=' + usemodel[i].icon + '></span>' +
                                '<span class="title">' + usemodel[i].name + '</span></a></li>';
                        }
                        num = num + 1;
                    } else if (appid == 10) {
                        if (document.location.href.indexOf(usemodel[i].url) > -1) {
                            menu = menu + '<li class="menu_item"><a href="/FirePM/manholecover/html/biz' + usemodel[i].url + '"><div style="width: 100%;padding-left: 25%;" class="menu_text"><span style="font-size: 20px;margin-right: 10px;" class=' + usemodel[i].icon + '></span>' + usemodel[i].name + '</div></a></li>';
                        } else {
                            menu = menu + '<li class="menu_item"><a href="/FirePM/manholecover/html/biz' + usemodel[i].url + '"><div style="width: 100%;padding-left: 25%;" class="menu_text"><span style="font-size: 20px;margin-right: 10px;" class=' + usemodel[i].icon + '></span>' + usemodel[i].name + '</div></a></li>';
                        }
                        num = num + 1;
                    } else if (appid == 19) {
                        if (document.location.href.indexOf(usemodel[i].url) > -1) {
                            menu = menu + '<li class="menu_item "><div class="underline"></div><a href="/FirePM/firedevice/html' + usemodel[i].url + '"><span class=' + usemodel[i].icon + '></span>' +
                                '<span class="title">' + usemodel[i].name + '</span></a></li>';
                        } else {
                            menu = menu + '<li class="menu_item active"><div class="underline"></div><a href="/FirePM/firedevice/html' + usemodel[i].url + '"><span class=' + usemodel[i].icon + '></span>' +
                                '<span class="title">' + usemodel[i].name + '</span></a></li>';
                        }
                    } else if (appid == 20) {
                        if (document.location.href.indexOf(usemodel[i].url) > -1) {
                            menu = menu + '<li class="menu_item "><div class="underline"></div><a href="/FirePM/firedraught/html' + usemodel[i].url + '"><span class=' + usemodel[i].icon + '></span>' +
                                '<span class="title">' + usemodel[i].name + '</span></a></li>';
                        } else {
                            menu = menu + '<li class="menu_item active"><div class="underline"></div><a href="/FirePM/firedraught/html' + usemodel[i].url + '"><span class=' + usemodel[i].icon + '></span>' +
                                '<span class="title">' + usemodel[i].name + '</span></a></li>';
                        }
                    } else if (appid == 21) {
                        if (document.location.href.indexOf(usemodel[i].url) > -1) {
                            menu = menu + '<li class="menu_item "><div class="underline"></div><a href="/FirePM/firepumpinfo/html' + usemodel[i].url + '"><span class=' + usemodel[i].icon + '></span>' +
                                '<span class="title">' + usemodel[i].name + '</span></a></li>';
                        } else {
                            menu = menu + '<li class="menu_item active"><div class="underline"></div><a href="/FirePM/firepumpinfo/html' + usemodel[i].url + '"><span class=' + usemodel[i].icon + '></span>' +
                                '<span class="title">' + usemodel[i].name + '</span></a></li>';
                        }
                    } else if (appid == 22) {
                        if (document.location.href.indexOf(usemodel[i].url) > -1) {
                            menu = menu + '<li class="menu_item "><div class="underline"></div><a href="/FirePM/waterater/html' + usemodel[i].url + '"><span class=' + usemodel[i].icon + '></span>' +
                                '<span class="title">' + usemodel[i].name + '</span></a></li>';
                        } else {
                            menu = menu + '<li class="menu_item active"><div class="underline"></div><a href="/FirePM/waterater/html' + usemodel[i].url + '"><span class=' + usemodel[i].icon + '></span>' +
                                '<span class="title">' + usemodel[i].name + '</span></a></li>';
                        }
                    } else if (appid == 12) {
                        if (document.location.href.indexOf(usemodel[i].url) > -1) {
                            menu = menu + '<li class="menu_item "><div class="underline"></div><a href="/esac/inspection/html' + usemodel[i].url + '"><span class=' + usemodel[i].icon + '></span>' +
                                '<span class="title">' + usemodel[i].name + '</span></a></li>';
                        } else {
                            menu = menu + '<li class="menu_item active"><div class="underline"></div><a href="/esac/inspection/html' + usemodel[i].url + '"><span class=' + usemodel[i].icon + '></span>' +
                                '<span class="title">' + usemodel[i].name + '</span></a></li>';
                        }
                    } else if (appid == 18) {
                        if (document.location.href.indexOf(usemodel[i].url) > -1) {
                            menu = menu + '<li class="menu_item active" ><a href="/FirePM/electrfire/html' + usemodel[i].url + '"><span class=' + usemodel[i].icon + '></span>' +
                                '<span class="title">' + usemodel[i].name + '</span></a></li>';
                        } else {
                            menu = menu + '<li><a href="/FirePM/electrfire/html' + usemodel[i].url + '"><span class=' + usemodel[i].icon + '></span>' +
                                '<span class="title">' + usemodel[i].name + '</span></a></li>';
                        }
                    } else if (appid == 23) {
                        if (document.location.href.indexOf(usemodel[i].url) > -1) {
                            menu = menu + '<li class="menu_item "><div class="underline"></div><a href="/FirePM/gasmonitoring/html' + usemodel[i].url + '"><span class=' + usemodel[i].icon + '></span>' +
                                '<span class="title">' + usemodel[i].name + '</span></a></li>';
                        } else {
                            menu = menu + '<li class="menu_item active"><div class="underline"></div><a href="/FirePM/gasmonitoring/html' + usemodel[i].url + '"><span class=' + usemodel[i].icon + '></span>' +
                                '<span class="title">' + usemodel[i].name + '</span></a></li>';
                        }
                    } else if (appid == 26) {
                        if (document.location.href.indexOf(usemodel[i].url) > -1) {
                            menu = menu + '<li class="menu_item"><a href="/FirePM/geomagnetism/html/biz' + usemodel[i].url + '"><div style="width: 100%;padding-left: 25%;" class="menu_text"><span style="font-size: 20px;margin-right: 10px;" class=' + usemodel[i].icon + '></span>' + usemodel[i].name + '</div></a></li>';
                        } else {
                            menu = menu + '<li class="menu_item"><a href="/FirePM/geomagnetism/html/biz' + usemodel[i].url + '"><div style="width: 100%;padding-left: 25%;" class="menu_text"><span style="font-size: 20px;margin-right: 10px;" class=' + usemodel[i].icon + '></span>' + usemodel[i].name + '</div></a></li>';
                        }
                        num = num + 1;
                    } else if (appid == 27) {
                        if (document.location.href.indexOf(usemodel[i].url) > -1) {
                            menu = menu + '<li class="menu_item"><a href="/FirePM/soak/html/biz' + usemodel[i].url + '"><div style="width: 100%;padding-left: 25%;" class="menu_text"><span style="font-size: 20px;margin-right: 10px;" class=' + usemodel[i].icon + '></span>' + usemodel[i].name + '</div></a></li>';
                        } else {
                            menu = menu + '<li class="menu_item"><a href="/FirePM/soak/html/biz' + usemodel[i].url + '"><div style="width: 100%;padding-left: 25%;" class="menu_text"><span style="font-size: 20px;margin-right: 10px;" class=' + usemodel[i].icon + '></span>' + usemodel[i].name + '</div></a></li>';
                        }
                        num = num + 1;
                    } else if (appid == 29) {
                        if (document.location.href.indexOf(usemodel[i].url) > -1) {
                            menu = menu + '<li class="menu_item "><div class="underline"></div><a href="/FirePM/socket/html' + usemodel[i].url + '"><span class=' + usemodel[i].icon + '></span>' +
                                '<span class="title">' + usemodel[i].name + '</span></a></li>';
                        } else {
                            menu = menu + '<li class="menu_item active"><div class="underline"></div><a href="/FirePM/socket/html' + usemodel[i].url + '"><span class=' + usemodel[i].icon + '></span>' +
                                '<span class="title">' + usemodel[i].name + '</span></a></li>';
                        }
                    }
                }

            }
            /*else if (usemodel[i].type == 3 && usemodel[i].status == 1 && usemodel[i].appid == 17) {
                            console.log(usemodel[i]);
                             if (document.location.href.indexOf(usemodel[i].url) > -1) {
                                 menu = menu + '<li class="menu_item active" ><a href="/waterq/waterquality/html' + usemodel[i].url + '"><span class=' + usemodel[i].icon + '></span>' +
                                     '<span class="title">' + usemodel[i].name + '</span></a></li>';
                             } else {
                                 menu = menu + '<li><a href="/waterq/waterquality/html' + usemodel[i].url + '"><span class=' + usemodel[i].icon + '></span>' +
                                     '<span class="title">' + usemodel[i].name + '</span></a></li>';
                             }
                             num = num + 1;
                         }*/

        }
        $('#menu ul').html(menu);
        $('#sidebar ul').append(menu);
        /*         if (num > 0) {
                     $('.profile-info div button').eq(0).css('display', 'inline-block')
                 };*/
    }
}

//后台管理系统中侧边栏显示哪些模块的函数
function superrootmodules() {
    var bootmanager = 0;
    if (localStorage.getItem("isLogin")) {
        var usemodel = JSON.parse(localStorage.getItem("isLogin")).ui;
        var num = 0;
        var menu = '<ul>'
        for (var i = 0; i < usemodel.length; i++) {
            if (usemodel[i].type == 2 && usemodel[i].status == 1) {

                if (document.location.href.indexOf(usemodel[i].url) > -1) {
                    menu = menu + '<li class="menu_item active" ><a href="/FirePM/superroot/html/biz' + usemodel[i].url + '"><span class=' + usemodel[i].icon + '></span>' +
                        '<div class="menu_text">' + usemodel[i].name + '</div></a></li>';
                } else {
                    menu = menu + '<li class="menu_item" ><a href="/FirePM/superroot/html/biz' + usemodel[i].url + '"><span class=' + usemodel[i].icon + '></span>' +
                        '<div class="menu_text">' + usemodel[i].name + '</div></a></li>';
                }
                num = num + 1;
            }
        }
        menu = menu + '</ul>'
        $('#menu').append(menu);
        if (num > 0) {
            $('#log_system_btn').css('display', 'inline-block')
        }
    }

}

/*function showpop(firedoorflag) {

    if (firedoorflag == 1) {
        firedoorwarnnum();

    }
}*/



function hideMenu() {
    if (localStorage.getItem("isLogin")) {
        var menuarr = JSON.parse(localStorage.getItem("isLogin")).ui;
        var menucount = 0;
        for (var i = 0; i < menuarr.length; i++) {
            if (menuarr[i].type == 2) {

                menucount = menucount + 1;
            }

        }
        if (menucount == 0) {
            $('#back_stage_button').hide();
        }
    }

    var args = new Object();
    args = GetUrlParms();
    if (args["url"] == 'agileadd') {
        $('#head-div').hide();
        $('#menu').hide();
        $('#header').hide();
        $('#sidebar').hide();
        $('.left-content').css("width", "98%");
    }
}

function GetUrlParms() {
    var args = new Object();
    var query = location.search.substring(1); //获取查询串 
    var pairs = query.split("&"); //在逗号处断开 
    for (var i = 0; i < pairs.length; i++) {
        var pos = pairs[i].indexOf('='); //查找name=value 
        if (pos == -1) continue; //如果没有找到就跳过 
        var argname = pairs[i].substring(0, pos); //提取name 
        var value = pairs[i].substring(pos + 1); //提取value 
        args[argname] = unescape(value); //存为属性 
    }
    return args;
}


function autoWarn() {
    layer.open({
        type: 1,
        offset: 'rb' //具体配置参考：offset参数项
            ,
        content: '<div style="padding: 20px 80px;">内容</div>',
        btn: '关闭全部',
        btnAlign: 'c' //按钮居中
            ,
        shade: 0 //不显示遮罩
            ,
        yes: function() {
            layer.closeAll();
        }
    });
}

function getAppName(appid) {
    var projectname;
    if (appid == 1) {
        projectname = '消火栓';
    } else if (appid == 2) {
        projectname = '喷淋末端';
    } else if (appid == 5) {
        projectname = '消防水池水箱';
    } else if (appid == 6) {
        projectname = '烟雾报警器';
    } else if (appid == 7) {
        projectname = '消防泵';
    } else if (appid == 9) {
        projectname = '门磁设备';
    } else if (appid == 16) {
        projectname = '电气火灾设备';
    } else if (appid == 18) {
        projectname = '电气火灾监测';
    } else if (appid == 19) {
        projectname = '火灾自动报警';
    } else if (appid == 20) {
        projectname = '消防风机';
    } else if (appid == 21) {
        projectname = '消防泵信息';
    } else if (appid == 22) {
        projectname = '消防用水量';
    } else if (appid == 23) {
        projectname = '可燃气体监测';
    } else if (appid == 26) {
        projectname = '地磁车位监测';
    } else if (appid == 27) {
        projectname = '浸水监测';
    } else if (appid == 28) {
        projectname = '火眼监测';
    };
    return projectname;
}
///websorket实时报警

function initWebSocket() {
    if (!window.WebSocket) {
        return false;
    }

    if (userId == null || userId == "") {
        return false;
    }
    //webSocket = new WebSocket("ws://192.168.0.148:8088/rest/websocket/" + userId);
    webSocket = new WebSocket("ws://websocket.njdtwise.com:8088/websocket/" + userId);

    webSocket.onopen = function(evt) {
        tryTime = 0;
    };

    webSocket.onmessage = function(msg) {
        msg = eval("(" + msg.data + ")");
        if (msg.data == "&") {

        } else {

            layer.open({
                title: '<span style="color:red;font-weight:bold;margin-right: 10px;">警告</span><i style="color: red;" class="fa fa-bullhorn"></i>',
                type: 1,
                offset: 'rb',
                area: '300px',
                move: false,
                content: '<div style="padding: 20px;"><span><i style="width:18px;color: green;" class="fa fa-cubes">' +
                    '</i>设备类型：</span><span style="font-family: 黑体;">' + getAppName(msg.appid) + '</span></br>' +
                    '<span><i style="width:18px;color: red;" class="fa fa-exclamation-triangle"></i>报警原因：</span>' +
                    '<span style="font-family: 黑体;">' + msg.eventType + '</span></br>' +
                    '<i style="width:18px;color: gray;" class="fa fa-clock-o"></i>上报时间：</span>' +
                    '<span style="font-family: 黑体;">' + msg.eventTime + '</span></br>' +
                    '<i style="width:18px;color: #ed741b;" class="fa fa-user"></i>负责人：</span>' +
                    '<span style="font-family: 黑体;">' + (msg.chargeperson == undefined ? '暂无' : msg.chargeperson) + '</span></br>' +
                    '<i style="width:18px;color: #854cd7;" class="fa fa-phone-square"></i>联系方式：</span>' +
                    '<span style="font-family: 黑体;">' + (msg.chargetele == undefined ? '暂无' : msg.chargetele) + '</span></br>' +
                    '<i style="width:18px;color: black;" class="fa fa-location-arrow"></i>安装地址：</span>' +
                    '<span style="font-family: 黑体;">' + msg.address + '</span>' +
                    '</div><audio autoplay="autoplay"><source src="http://www.njdtwise.com/FirePM/static/img/video/fire.ogg" type="audio/ogg"><source src="http://www.njdtwise.com/FirePM/static/img/video/fire.mp3" type="audio/mpeg"></audio>',
                shade: 0, //不显示遮罩
            });
        }
    };

    webSocket.onerror = function(evt) {};

    webSocket.onclose = function() {
        // 重试2次，每次之间间隔2秒
        if (tryTime < 4) {
            setTimeout(function() {
                webSocket = null;
                tryTime++;
                initWebSocket();
            }, 5 * 1000);
        } else {}
    };
}

function closeWebSocket() {
    if (webSocket) {
        webSocket.close();
    }
}

function includeJS() {
    isLogin = localStorage.getItem('isLogin');
    if (isLogin != null && isLogin != "") {
        var obj = JSON.parse(localStorage.getItem("isLogin"));
        var orgid = isLogin.orgid;
    }

    var script = document.createElement("script");
    script.type = "text/javascript";
    if (orgid == 110) {
        script.src = "../static/js/config/qx_config.js";
    } else {
        script.src = "../static/js/config/normal.js";
    }
    document.getElementsByTagName('head')[0].appendChild(script);
}